<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>

<body>
    最大值：
    <input type="text" id="max"><br>
    最小值：
    <input type="text" id="min"><br>
    数量：
    <input type="text" id="num"><br>

    <input type="button" value="生成" id="btn1"><span></span><br>
    <input type="button" value="去重" id="btn2"><span></span><br>
    <input type="button" value="排序" id="btn3"><span></span>
</body>
<script>
    const max = document.getElementById("max");
    const min = document.getElementById("min");
    const num = document.getElementById("num");
    const btn1 = document.getElementById("btn1");
    const btn2 = document.getElementById("btn2");
    const btn3 = document.getElementById("btn3");

    btn1.onclick = function () {
        let arr = [];
        console.log(max.value)
        console.log(min.value)
        let aaa = parseInt(max.value)
        let bbb = parseInt(min.value)
        for (i = 0; i <= num.value - 1; i++) {
            arr.push(random(aaa, bbb))
        }
        console.log(arr)
        btn1.nextElementSibling.innerHTML = arr.join("-")

        btn2.onclick = function () {
            // console.log(norepeat(arr))
            var ccc= norepeat(arr);
            btn2.nextElementSibling.innerHTML = ccc.join("-");
            btn3.onclick = function () {
                for (i = 0; i < ccc.length - 1; i++) {
                    for (j = 0; j <= ccc.length - 1 - i; j++) {
                        if (ccc[j] > ccc[j + 1]) {
                            [ccc[j], ccc[j + 1]] = [ccc[j + 1], ccc[j]]
                        }
                    }
                }
                btn3.nextElementSibling.innerHTML=ccc.join("-")
            }
        }

    }

    // 封装的函数区域
    function random(a, b) {
        return Math.round(Math.random() * (a - b) + b);
    }
    function has(a, d) {
        for (var i = 0; i < a.length; i++) {
            if (a[i] === d) {
                return true;
            }
        }
        return false;
    }
    function norepeat(a) {
        var newArr = [];
        for (var i = 0; i < a.length; i++) {
            if (!has(newArr, a[i])) {
                newArr.push(a[i]);
            }
        }
        return newArr;
    }


</script>

</html>